package com.itljm.cxrMarket.controller;

import com.itljm.cxrMarket.common.Result;
import com.itljm.cxrMarket.service.SysUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ljm
 * @date 2024/12/17 21:46
 */
@RestController
@RequestMapping("/sysUserRole")
@CrossOrigin
public class SysUserRoleController {
    @Autowired
    private SysUserRoleService sysUserRoleService;

    /**
     * 分配角色给用户
     */
    @PostMapping("/{userId}/roles")
    public Result assignRolesToUser(@PathVariable Long userId, @RequestBody List<Long> roleIds) {
        sysUserRoleService.assignRolesToUser(userId, roleIds);
        return Result.ok();
    }

    /**
     * 获取用户的角色列表
     */
    @GetMapping("/{userId}/roles")
    public Result getUserRoles(@PathVariable Long userId) {
        List<String> roles = sysUserRoleService.getUserRoles(userId);
        return Result.ok(roles);
    }
}
